package com.ruoyi.gams.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.gams.domain.GamsStaff;
import com.ruoyi.gams.service.IGamsStaffService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 员工Controller
 *
 * @author ruoyi
 * @date 2021-09-03
 */
@RestController
@RequestMapping("/gams/staff")
public class GamsStaffController extends BaseController
{
    @Autowired
    private IGamsStaffService gamsStaffService;

    /**
     * 查询员工列表
     */
    @PreAuthorize("@ss.hasPermi('gams:staff:list')")
    @GetMapping("/list")
    public TableDataInfo list(GamsStaff gamsStaff)
    {
        startPage();
        List<GamsStaff> list = gamsStaffService.selectGamsStaffList(gamsStaff);
        return getDataTable(list);
    }

    /**
     * 导出员工列表
     */
    @PreAuthorize("@ss.hasPermi('gams:staff:export')")
    @Log(title = "员工", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GamsStaff gamsStaff)
    {
        List<GamsStaff> list = gamsStaffService.selectGamsStaffList(gamsStaff);
        ExcelUtil<GamsStaff> util = new ExcelUtil<GamsStaff>(GamsStaff.class);
        return util.exportExcel(list, "员工数据");
    }

    /**
     * 获取员工详细信息
     */
    @PreAuthorize("@ss.hasPermi('gams:staff:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(gamsStaffService.selectGamsStaffById(id));
    }

    /**
     * 新增员工
     */
    @PreAuthorize("@ss.hasPermi('gams:staff:add')")
    @Log(title = "员工", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GamsStaff gamsStaff)
    {
        return toAjax(gamsStaffService.insertGamsStaff(gamsStaff));
    }

    /**
     * 修改员工
     */
    @PreAuthorize("@ss.hasPermi('gams:staff:edit')")
    @Log(title = "员工", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GamsStaff gamsStaff)
    {
        return toAjax(gamsStaffService.updateGamsStaff(gamsStaff));
    }

    /**
     * 删除员工
     */
    @PreAuthorize("@ss.hasPermi('gams:staff:remove')")
    @Log(title = "员工", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(gamsStaffService.deleteGamsStaffByIds(ids));
    }
}
